package edu.map.aamas.gui;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;

import edu.map.aamas.charts.ActuationChart;
import edu.map.aamas.charts.AngularSpeedChart;
import edu.map.aamas.charts.ForceChart;
import edu.map.aamas.charts.MeanSpeedChart;
import edu.map.aamas.charts.PositionChart;
import edu.map.aamas.charts.SpeedChart;
import edu.map.aamas.charts.TailAngleChart;
import edu.map.aamas.gui.tablelayout.TableLayout;
import edu.map.aamas.rnn.RNN;

public class MainPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	private RNN rnr;
	private PondPanel pond;
	private ActuationChart actuation;
	private ForceChart force;
	private RnnEvolutionDisplay evolution;
	private ConnectionMatrix matrix;
	private SpeedChart speed;
	private PositionChart position;
	private MeanSpeedChart meanSpeed;
	private TailAngleChart tailAngle;
	private AngularSpeedChart angularSpeed;
	
	public MainPanel() {
		rnr = RNN.getInstance(32);
		setLayout(new TableLayout(new double[] {10, 0.5, 10, 0.5, 10}, new double[] {10, 40, 10, 0.4, 10, 0.15, 10, 0.15, 10, 0.15, 10, 0.15, 10}));
		
		pond = PondPanel.getInstance();
		pond.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
		rnr.addRnrListener(pond);
		
		actuation = new ActuationChart(rnr);
		actuation.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
		rnr.addRnrListener(actuation);
		
		force = new ForceChart(rnr);
		force.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
		rnr.addRnrListener(force);
		
		speed = new SpeedChart(rnr);
		speed.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
		rnr.addRnrListener(speed);
		
		matrix = new ConnectionMatrix(rnr);
		matrix.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));		
		rnr.addRnrListener(matrix);
		
		evolution = new RnnEvolutionDisplay();
		evolution.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));		
		rnr.addRnrListener(evolution);
		
		position = new PositionChart(rnr);
		position.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
		rnr.addRnrListener(position);
		
		meanSpeed = new MeanSpeedChart(rnr);
		meanSpeed.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
		rnr.addRnrListener(meanSpeed);
		
		tailAngle = new TailAngleChart(rnr);
		tailAngle.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
		rnr.addRnrListener(tailAngle);
		
		angularSpeed = new AngularSpeedChart(rnr);
		angularSpeed.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
		rnr.addRnrListener(angularSpeed);
		
		this.add(new ControlPanel(rnr), "1,1 3,1");
		this.add(pond, "1,3, 3,3");
		this.add(matrix, "1,5");
		this.add(evolution, "3,5");
		//this.add(actuation, "1,5");
		//this.add(force, "3,5");
		this.add(speed, "1,7");
		this.add(meanSpeed, "3,7");
		this.add(position, "1,9");
		this.add(angularSpeed, "3,9");		
	}
	
	public static void main(String[] args) throws Exception{
		JFrame test = new JFrame("RNR Test");		
		MainPanel panel = new MainPanel();
		test.setSize(480, 640);
		test.add(panel);
		test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		test.setVisible(true);
		panel.rnr.init();
		panel.rnr.resume();
	}
	
}
